﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class DNHundredPanel : MonoBehaviour {

    public GameObject exitBtn;
    public GameObject trendBtn;
    public GameObject playersBtn;
    public GameObject chatBtn;
    public GameObject bankerUpBtn;
    public GameObject bankerDownBtn;
    public List<GameObject> betBtns;

    public DNHundredGame dnGame;

    public bool isCanBet;
	void Awake () {
        UIEventListener.Get(exitBtn).onClick = ButtonClick;
        UIEventListener.Get(trendBtn).onClick = ButtonClick;
        UIEventListener.Get(playersBtn).onClick = ButtonClick;
        UIEventListener.Get(chatBtn).onClick = ButtonClick;
        UIEventListener.Get(bankerUpBtn).onClick = ButtonClick;
        UIEventListener.Get(bankerDownBtn).onClick = ButtonClick;

        for (int i = 0; i < betBtns.Count;i++ )
        {
            UIEventListener.Get(betBtns[i]).onClick = ButtonClick;
        }
	}

    void ButtonClick(GameObject button)
    {
        if (button.name == "ExitBtn")
        {
            //退出
            RoomLeaveRequest rl = new RoomLeaveRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(rl,MsgId.RoomLeaveRequest);
        }
        else if (button.name == "TrendBtn")
        {
            //走势图
            Nn100HistoryRequest nh = new Nn100HistoryRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(nh, MsgId.Nn100HistoryRequest);
        }
        else if (button.name == "PlayersBtn")
        {
            //玩家列表
            Nn100StandListRequest ns = new Nn100StandListRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(ns, MsgId.Nn100StandListRequest);
        }
        else if (button.name == "ChatBtn")
        {
            //聊天
            GameObject chat = NGUITools.AddChild(GameObject.Find("UI Root"),(GameObject)Resources.Load(GameDN100PrefabPath.Chat));
        }
        else if (button.name == "BankerUpBtn")
        {
            //上庄
            Nn100BankerRequest nb = new Nn100BankerRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(nb,MsgId.Nn100BankerRequest);
        }
        else if (button.name == "BankerDownBtn")
        {
            //下庄
            Debug.Log("下庄");
            Nn100CancelBankerRequest nc = new Nn100CancelBankerRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(nc, MsgId.Nn100CancelBankerRequest);
        }
        //下注
        else if(button.transform.parent.name == "Tian"){
            SendBetRequest(1);
        }
        else if (button.transform.parent.name == "Di")
        {
            SendBetRequest(2);
        }
        else if (button.transform.parent.name == "Xuan")
        {
            SendBetRequest(3);
        }
        else if (button.transform.parent.name == "Huang")
        {
            SendBetRequest(4);
        }
               
    }


    void SendBetRequest(int betPosition)
    {
        //if(isCanBet == true)
        {
            Debug.Log("下注了");
            Nn100BetRequest nb = new Nn100BetRequest { BetPosition = betPosition, BetCoinCount = dnGame.betCoinCount };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(nb, MsgId.Nn100BetRequest);
        }
       
    }
}
